const { defineConfig } = require("@vue/cli-service");
const { list, car } = require("./src/mock");
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    setupMiddlewares(middle, { app }) {
      app.get("/api/list", (req, res) => {
        res.send({
          code: 200,
          data: list,
        });
      });

      app.get("/api/car", (req, res) => {
        res.send({
          code: 200,
          data: car,
        });
      });

      app.get("/api/car/detail", (req, res) => {
        const { id } = req.query;

        car.forEach((v) => {
          const result = v.list.find((item) => {
            return item.id === id;
          });

          if (result) {
            res.send({
              code: 200,
              data: result,
            });
          }
        });
      });

      return middle;
    },
  },
});
